package com.zhang.demo.spring.init;

import com.zhang.demo.spring.bean.User;
import com.zhang.demo.spring.bean.UserAttr;
import com.zhang.demo.spring.bean.annotation.UserService;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;
import org.springframework.context.support.GenericApplicationContext;
import org.springframework.context.support.GenericXmlApplicationContext;

public class SpringInitTest {

    public static void main(String[] args) {

        //地址必须是绝对或者相对地址
       // ApplicationContext fileSystemXmlApplicationContext = new FileSystemXmlApplicationContext("E:\\code\\workcode\\develop\\springExample\\src\\main\\resources\\ioc.xml");

        ApplicationContext fileSystemXmlApplicationContext = new FileSystemXmlApplicationContext("src/main/resources/ioc.xml");


        UserAttr userAttr = fileSystemXmlApplicationContext.getBean(UserAttr.class);

        System.out.println(userAttr);

        ApplicationContext classPathXmlApplicationContext = new ClassPathXmlApplicationContext("ioc.xml");

        UserAttr userAttr1 = (UserAttr) classPathXmlApplicationContext.getBean("userAttr");
        System.out.println(userAttr1);

        AnnotationConfigApplicationContext annotationConfigApplicationContext =
                new AnnotationConfigApplicationContext("com.zhang.demo.spring.bean.annotation");


        UserService user = (UserService) annotationConfigApplicationContext.getBean("userService");

        System.out.println(user);

        //ApplicationContext genericXmlApplicationContext = new GenericXmlApplicationContext("ioc.xml");

        ApplicationContext genericXmlApplicationContext = new GenericXmlApplicationContext("ioc.xml");
        UserAttr userAttr2 = genericXmlApplicationContext.getBean(UserAttr.class);
        System.out.println(userAttr2);



    }




}
